home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / hershey / src / hdisp.c < prev    next >
C/C++ Source or Header  |  1994-04-12  |  2KB  |  142 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include <gl.h>
  5. #include <device.h>
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. #include "hershey.h"
  12.  
  13. #ifdef __PROTOTYPE__
  14. int getcharacter( FILE *, int *, int *, char *);       /* getchar.c       */
  15. #else
  16. extern int getcharacter();                             /* getchar.c       */
  17. #endif
  18.  
  19. extern int    getcharacter();
  20.  
  21. #define    XCOORD(x)    ((int)(x) - (int)'R')
  22. #define    YCOORD(y)    ((int)'R' - (int)(y))    /* invert as in tv coords */
  23.  
  24. /*
  25.  * newpage
  26.  *
  27.  *    draw up a new page with title, boxes, etc..
  28.  */
  29. int newpage(
  30.   char *fname,
  31.   int pageno)
  32. {
  33.     char    str[100];
  34.  
  35.     hcentertext(0);
  36.  
  37.     htextsize(0.05, 0.07);
  38.  
  39.     move2(-0.91, 0.9);
  40.     hcharstr("Hershey Character File: ");
  41.     hcharstr(fname);
  42.  
  43.     move2(0.45, 0.9);
  44.     sprintf(str, "Page No: %d", pageno);
  45.     hcharstr(str);
  46.  
  47.     htextsize(0.03, 0.03);
  48.  
  49.     hcentertext(1);
  50. }
  51.  
  52. /*
  53.  * display the hershey data set in the input file.
  54.  */
  55. int main(
  56.   int ac,
  57.   char **av)
  58. {
  59.     FILE    *fp;
  60.     int    charno, numpairs, page;
  61.     char    c, device[20], buf[1000], *p, str[100];
  62.     float    x, y, ox, oy;
  63.     short    val;
  64.  
  65.     if (ac < 2) {
  66.         fprintf(stderr, "hdisp: usage hdisp datafile\n");
  67.         exit(1);
  68.     }
  69.  
  70.     if ((fp = fopen(av[1], "r")) == NULL) {
  71.         fprintf(stderr, "hdisp: unable to open file %s\n", av[1]);
  72.         exit(1);
  73.     }
  74.  
  75.     hfont("times.r");
  76.  
  77.     winopen("hdisp");
  78.     qdevice(KEYBD);
  79.     ortho2(-1.0, 1.0, -1.0, 1.0);
  80.  
  81.     color(BLACK);
  82.     clear();
  83.  
  84.     ox = -0.8;
  85.     oy = 0.75;
  86.  
  87.     page = 1;
  88.  
  89.     color(WHITE);
  90.  
  91.     newpage(av[1], page);
  92.  
  93.     while (getcharacter(fp, &charno, &numpairs, buf)) {
  94.  
  95.         if (buf[2] != 0) {
  96.             p = &buf[2];        /* skip the width bytes */
  97.  
  98.             x = XCOORD(*p++) / 280.0;
  99.             y = YCOORD(*p++) / 280.0;
  100.             move2((Coord)(ox + x), (Coord)(oy + y));
  101.  
  102.             while (*p != 0) {
  103.                 if (*p == ' ') {
  104.                     p += 2;
  105.                     x = XCOORD(*p++) / 280.0;
  106.                     y = YCOORD(*p++) / 280.0;
  107.                     move2((Coord)(ox + x), (Coord)(oy + y));
  108.                 } else {
  109.                     x = XCOORD(*p++) / 280.0;
  110.                     y = YCOORD(*p++) / 280.0;
  111.                     draw2((Coord)(ox + x), (Coord)(oy + y));
  112.                 }
  113.             }
  114.         }
  115.  
  116.         move2((Coord)ox, (Coord)(oy - 0.11));
  117.         sprintf(str, "(%d)", charno);
  118.         hcharstr(str);
  119.  
  120.         ox += 0.22;
  121.         if (ox > 0.9) {
  122.             oy -= 0.22;
  123.             ox = -0.8;
  124.         }
  125.         if (oy < -0.9) {
  126.             oy = 0.75;
  127.             qread(&val);
  128.  
  129.             color(BLACK);
  130.             clear();
  131.  
  132.             color(WHITE);
  133.  
  134.             newpage(av[1], ++page);
  135.         }
  136.     }
  137.  
  138.     qread(&val);
  139.  
  140.     gexit();
  141. }
  142.